home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Low Level Languages / Rm Cobol V2.2 / ASMTST.ASM next >
Encoding:
Assembly Source File  |  1985-09-19  |  5.0 KB  |  153 lines

  1.     page    63, 132
  2.     title ASMTST - used to test machine language links to RM/COBOL
  3.     name    asmtst
  4. ;************************************************************************
  5. ;*                ASMTST                    *
  6. ;*                                    *
  7. ;*    Program written by: Ryan-McFarland    Date: 84.03.28        *
  8. ;*                        Updated: 85.04.10    *
  9. ;*            (Safety check added to loop counter CX)        *
  10. ;*                        Updated: 85.07.31    *
  11. ;*            (Reworked source from CP/M-86 to DOS assembler)    *
  12. ;*                                    *
  13. ;*    Description: Sample program to illustrate machine language    *
  14. ;*        linkage to RM/COBOL.                    *
  15. ;*        The Runtime would be configured to automatically    *
  16. ;*        load this module at startup, by setting Link Addr to    *
  17. ;*        be equal to the offset of INITIAL. This would also    *
  18. ;*        force the Runtime to call the program INITIAL        *
  19. ;*        before the RM/COBOL program begins execution.        *
  20. ;*            INITIAL will copy the passed command        *
  21. ;*        line arguments to a local data space, and its work    *
  22. ;*        is finished. The RM/COBOL program, LNKTST, will        *
  23. ;*        later call ASMTST and have the saved            *
  24. ;*        command line arguments returned to the program        *
  25. ;*        LNKTST.                            *
  26. ;*    Parameters passed to ASMTST:                    *
  27. ;*        Register BX points to an argument list            *
  28. ;*        that has the structure:                    *
  29. ;*    ES:BX ->    DW Byte count of argments following (e.g = 4)    *
  30. ;*            DW OFFSET STRING-VALUE                *
  31. ;*            DW OFFSET STRING-LENGTH                *
  32. ;*        These two variables are in the calling RM/COBOL        *
  33. ;*        program. These offsets are relative to the        *
  34. ;*        segment register ES.                    *
  35. ;*                                    *
  36. ;*    ASMTST will move the string from its local space here to    *
  37. ;*        the RM/COBOL variable STRING-VALUE, and the length    *
  38. ;*        of this string to STRING-LENGTH.            *
  39. ;*        A return value is returned in register AL        *
  40. ;*        Zero if all OK, non-zero in case of error.        *
  41. ;************************************************************************
  42.     page
  43. CODE    SEGMENT    BYTE    PUBLIC    'CODE'
  44.     ASSUME    CS:CODE, DS:CODE
  45. MAIN    PROC    FAR
  46.     DW    ENDCODE        ;Length of module.
  47.     DB    7        ;Length of 'INITIAL'
  48.     DB    'INITIAL'    ;Program name
  49.     DW    INITIAL        ;Entry point
  50.     DB    6        ;Length of 'ASMTST'
  51.     DB    'ASMTST'    ;Program name
  52.     DW    ASMTST        ;Entry point
  53.     DB    0        ;End of table
  54. ;
  55. ;    Sccs information :
  56.         db    '@ #( ) (@)#@(#)'    ;SCCS id.
  57.         db    'asmtst.asm'        ;Program name % M %.
  58.         db    ' ver. '
  59.         db    '1.3'        ;version % I %.
  60.         db    ' 85/07/31 '        ;date % E %.
  61.         db    '15:27:17'        ;time % U %.
  62.         db    '>'        ;Ending indicator.
  63. ;    Local data area
  64. ;
  65. SPACE    EQU    020H        ;Value of blank space
  66. STRING    dB    20    dup (?)    ;20 bytes to save command line arguments.
  67. LNGTH    dB    2    dup (?)    ;A word for length of above string.
  68. ASMTST:
  69.                 ;ES:[BX] points to a byte count.
  70.     MOV    CL,ES:[BX]    ;Check the low order of the byte count.
  71.     CMP    CL,4        ;Byte count is 4 for 2 arguments.
  72.     JNZ    FAILURE        ;Argument count is not 4, calling error.
  73.                 ;Following the byte count is an argument list
  74.     MOV    DI,ES: 2 [BX]    ;DI points to COBOL variable 'STRING-VALUE'
  75.     MOV    SI,OFFSET STRING    ;String here is the source.
  76.     MOV    CX,WORD PTR LNGTH    ;And the length thereof.
  77.     CALL    CHECKCX        ;Force to within range [1,20]
  78. HERE:
  79.     MOV    AL,[SI]        ;Source
  80.     MOV    ES:[DI],AL    ;Destination
  81.     INC    SI
  82.     INC    DI
  83.     LOOP    HERE        ;Move string from here to COBOL
  84.                 ;address of 'STRING-LENGTH'.
  85.     MOV    DI,ES: 4 [BX]    ;DI points to COBOL variable
  86.                 ;'STRING-LENGTH'
  87.     MOV    AX,WORD PTR LNGTH    ;Transfer through AX
  88.     XCHG    AH,AL        ;COMP-1 variables are in straight
  89.                 ;byte order
  90.     MOV    ES:[DI],AX    ;Transfer string length to COBOL.
  91.     XOR    AX,AX        ;Clear AX for return code.
  92.     RET            ;Return far.
  93. FAILURE:
  94.     OR    AX,2        ;Return non-zero error code.
  95.     RET            ;And return far.
  96.     page
  97. SUBS    PROC    NEAR
  98. CHECKCX:
  99.     CMP    CX,0        ;CX should not be zero or below
  100.     JG    PASS1
  101.     MOV    CX,1        ;It is less than 1, force to 1
  102. PASS1:
  103.     CMP    CX,20        ;Should not be above 20
  104.     JLE    PASS2
  105.     MOV    CX,20        ;Force to 20
  106. PASS2:
  107.     MOV    WORD PTR LNGTH,CX    ;Update if changed
  108.     RET
  109. SUBS    ENDP
  110.     page
  111. ;
  112. ;    INITIAL is executed once at startup time.
  113. ;        it simply moves a string to local space.
  114. ;
  115. ;    Enters with SI pointing to a character string
  116. ;        and AL the length of that string.
  117. ;
  118. ;    Runtime configuration note: When using MASM and LINK on
  119. ;        this source, INITIAL has offset 0176 hex. This is the
  120. ;        value to be used for Link Addr when configuring
  121. ;        the runtime so that INITIAL will execute before the
  122. ;        RM/COBOL program begins execution
  123. ;
  124. INITIAL:
  125.     MOV    BYTE PTR LNGTH,AL    ;Length of the string
  126.     MOV    BYTE PTR LNGTH+1,00    ;High order byte is zero
  127.     MOV    DI,OFFSET STRING    ;String should be set to
  128.     MOV    AL,SPACE        ;blanks.
  129.     MOV    CX,20            ;Length of string
  130. BLANKS:
  131.     MOV    [DI],AL            ;Blank fill
  132.     INC    DI
  133.     LOOP    BLANKS
  134.     MOV    CX,WORD PTR LNGTH    ;Make sure that the string length
  135.     CALL    CHECKCX            ;Is in the range [1,20]
  136.     MOV    DI,OFFSET STRING    ;Reset DI to start of string
  137. LOOP1:
  138.     MOV    AL,ES:[SI]        ;SI points to command line characters
  139.     MOV    [DI],AL            ;DI points to local string
  140.     INC    SI
  141.     INC    DI        ;Move the string to our local variable space
  142.     LOOP    LOOP1
  143.     XOR    AL,AL            ;AL=0 for all ok signal, no abnormal
  144.                     ;exit
  145.     RET            ;Return far
  146. ENDCODE:
  147. MAIN    ENDP
  148. code    ends
  149. stack    segment    byte    stack    'stack'
  150.     assume    ss:stack
  151. stack    ends
  152.     END    INITIAL        ;Theoretical entry point if this was a normal program
  153.